<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加/修改账号</title>
<%@ include file="/view/common/tags.jsp"%>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" id="saveAndUpdateFrom" target="_parent" action="">
			<div class="form-group">
                <div class="form-group" >
                    <label class="col-xs-2 text-right">平台:</label>
                    <div class="col-xs-9">
                        <sk:select cssClass="form-control select" name="platformType" id="platformType" value="" requiredInit="true" ajaxURL="${sysManagerV1}/baseType/select?wm[PARENT_ID]=20">
                            <option value="">请选择</option>
                        </sk:select>
                        <input type="hidden" name="platformName" id="platformName" value="">
                    </div>
                </div>
				<div class="form-group" >
					<label class="col-xs-2 text-right">账号:</label>
					<div class="col-xs-9">
						<input type="text" class="form-control" name="userName" id="userName" value=""  placeholder="输入账号">
					</div>
				</div>
				<div class="form-group" >
					<label class="col-xs-2 text-right">密钥:</label>
					<div class="col-xs-9">
						<input type="text" class="form-control" name="userKey" id="userKey" value=""  placeholder="输入密钥">
					</div>
				</div>
				<div class="form-group" >
					<label class="col-xs-2 text-right">邮箱:</label>
					<div class="col-xs-9">
						<input type="text" class="form-control" name="userEmail" id="userEmail" value=""  placeholder="输入邮箱">
					</div>
				</div>
				<div class="form-group" >
					<label class="col-xs-2 text-right">邮箱密码:</label>
					<div class="col-xs-9">
						<input type="text" class="form-control" name="emailPwd" id="emailPwd" value=""  placeholder="输入邮箱密码">
					</div>
				</div>
				<div class="form-group" >
					<label class="col-xs-2 text-right">网站密码:</label>
					<div class="col-xs-9">
						<input type="text" class="form-control" name="loginPwd" id="loginPwd" value=""  placeholder="输入网站密码">
					</div>
				</div>
				<div class="form-group" >
					<label class="col-xs-2 text-right">支付密码:</label>
					<div class="col-xs-9">
						<input type="text" class="form-control" name="payPwd" id="payPwd" value=""  placeholder="输入支付密码">
					</div>
				</div>
				<div class="form-group" >
					<label class="col-xs-2 text-right">启用状态:</label>
					<div class="col-xs-9">
                        <label for="port"><input id="yse" name="userEnable" type="radio" value="0"/>&nbsp;启用</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label for="no"><input id="no" name="userEnable" type="radio" value="1"/>&nbsp;禁用</label>
					</div>
				</div>
			    
    			<input type="hidden" id="rowId" name="rowId" value="<%=request.getParameter("rowId")%>">
                <input type="hidden" id="token" name="token" value="">
    			<input type="hidden" id="flag"  value="${flag}">
    			<input type="hidden" id="isReCommit" value="0">
        	</div>
		</sk:form>	
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script type="text/javascript">
$(function(){
    var rowId = $("#rowId").val();
    $("#yse").attr("checked","true");
    if(rowId > 0){
        $.ajax({
            url: "${sysManagerV1}/cardUser/getUserDetail",
            type: "post",
            cache: false,
            data:{"rowId":rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data == null) {
                    return;
                }
                data = data.data;
                $("#platformType").val(data.platformType);
                $("#userName").val(data.userName);
                $("#userKey").val(data.userKey);
                $("#userEmail").val(data.userEmail);
                $("#emailPwd").val(data.emailPwd);
                $("#loginPwd").val(data.loginPwd);
                $("#payPwd").val(data.payPwd);
                if(data.userEnable == 0){
                    $("#yse").attr("checked","true");
                    $("#no").removeAttr("checked");
                } else {
                    $("#yse").removeAttr("checked");
                    $("#no").attr("checked","true");
                }
            }
        });
    }
    $("#token").val(sessionStorage.getItem("token"));
})

   var err = {'1':'添加','2':'修改'};
   var action = {'1':'/add','2':'/update'};
   function add(){
	    var rowId = $('#rowId').val();
	    var i;
	    if (!CheckUtil.isNotNull(rowId) || rowId == 0) {
	        i = 1;//添加
	    } else {
	        i = 2;//修改
	    }
	    
	    var platformType = $.trim($("#platformType").val());
	    if (!CheckUtil.isNotNull(platformType)) {
	        layer.msg("请选择平台!");
            $("#platformType").focus();
	        return;
	    }
	    $("#platformName").val($("#platformType option:selected").text());
	    
	    var userName = $.trim($("#userName").val());
        if (!CheckUtil.isNotNull(userName)) {
            layer.msg("请填写用户帐号!");
            $("#userName").focus();
            return;
        }
	    
	    var userKey = $.trim($("#userKey").val());
        if (!CheckUtil.isNotNull(userKey)) {
            layer.msg("请填写密钥!");
            $("#userKey").focus();
            return;
        }
	    
	    var userEmail = $.trim($("#userEmail").val());
        if (!CheckUtil.isNotNull(userEmail)) {
            layer.msg("请填写邮箱帐号!");
            $("#userEmail").focus();
            return;
        }
	    
	    var emailPwd = $.trim($("#emailPwd").val());
        if (CheckUtil.isNotNull(userEmail) && !CheckUtil.isNotNull(emailPwd)) {
            layer.msg("请填写邮箱密码!");
            $("#emailPwd").focus();
            return;
        }
	    
	    var loginPwd = $.trim($("#loginPwd").val());
        if (!CheckUtil.isNotNull(loginPwd)) {
            layer.msg("请填写登陆密码!");
            $("#loginPwd").focus();
            return;
        }
	    
	    var payPwd = $.trim($("#payPwd").val());
        if (!CheckUtil.isNotNull(payPwd)) {
            layer.msg("请填写支付密码!");
            $("#payPwd").focus();
            return;
        }
        
        var isExist = checkIsExist();
        if(isExist != 0){
            layer.msg("该配置已经存在!");
            return;
        }

        //loading层
        var index = layer.load(0, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        

        $.ajax({
            url: "${sysManagerV1}/cardUser/" + action[i],
            type: "post",
            cache: false,
            data: new FormData($("#saveAndUpdateFrom")[0]),
            dataType:"json",
            processData: false,
            contentType: false,
            async:false,
            success: function(data) {
                if(data.code == 0){
                    parent.layer.msg(err[i] + "成功！");
                } else if(data.code == "-2"){
                    parent.window.location.href="${sysManagerV1}/";
                } else {
                    parent.layer.msg(data.message);
                }
                if(data.code >= 0){
                    parent.findData();
                    parent.layer.close(parent.tableIndex);
                }
            }
        });
	}
   

function checkIsExist() {
    var platformType = $("#platformType").val();
    var userName = $("#userName").val();
    var rowId = $("#rowId").val();;
    var aa = false;
    if (CheckUtil.isNotNull(platformType) && CheckUtil.isNotNull(userName)) {
        $.ajax({
            type: "post",
            cache: false,
            url: "${userInfoV1}/cardUser/checkIsExist",
            data:{"platformType":platformType, "userName":userName, "rowId":rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                aa = data.code;
            }
        });
    }
    return aa;  
}
   </script>
</html>